package com.core.springSecurity.common;

import com.common.ErrorCodeEnum;
import com.common.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: zql
 * @Description: 设备指纹服务，鉴别访问设备唯一
 * @Data: 14:32 2021/7/13
 */
@Slf4j
public class FingerprintUtils {

    private static  ThreadLocal<String> fingerprintDeviceID = new ThreadLocal<String>();


    public static void setFingerprintDeviceID(String id) {
        if (fingerprintDeviceID == null) {
            fingerprintDeviceID = new ThreadLocal<String>();
            fingerprintDeviceID.remove();
        }
        fingerprintDeviceID.set(id);
    }

    public static String getFingerprintDeviceID() {
        String ctx = fingerprintDeviceID.get();
        if (ctx == null) {
            log.error("指纹不存在");
            throw new BusinessException(ErrorCodeEnum.FINGERPRINT_NOT_FOUND);
        }
        return ctx;
    }


}
